<template>
  <a-card :bordered="false">
    <a-spin :spinning="confirmLoading">
      <a-form-model ref="form" :model="model" :rules="validatorRules">
        <a-card title="社交奖励" :bordered="false">
          <a-col :span="24">
            <a-form-model-item label="社交收益(%)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="SocialBenefits">
              <a-input v-model="model.SocialBenefits" placeholder="请输入社交收益(%)"></a-input>
            </a-form-model-item>
            <a-form-model-item v-bind="formItemLayoutWithOutLabel">
              女用户与其他用户聊天，女用户得到的社交收益比例。<br/>
              例：社交收益（%）=40%，女用户与其他用户聊天时，其他用户给女用户送礼物/聊天消费了100金币，则女用户的社交奖励=100*40%=40钻石
            </a-form-model-item>
          </a-col>
        </a-card>

        <a-card :bordered="false">
          <div slot="title">
            <span>会员奖励</span>
            <span style="font-size: 12px;color: #9e9e9e">（按照 1块钱=100钻石  的固定兑换比例计算上级收益）</span>
          </div>
          <a-row>
            <a-col :span="24">
              <a-form-model-item label="直推上级收益(%)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="SuperiorBenefits">
                <a-input v-model="model.SuperiorBenefits" placeholder="请输入直推上级收益(%)"></a-input>
              </a-form-model-item>
              <a-form-model-item label="间推上级收益(%)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="UnSuperiorBenefits">
                <a-input v-model="model.UnSuperiorBenefits" placeholder="请输入间推上级收益(%)"></a-input>
              </a-form-model-item>
              <a-form-model-item v-bind="formItemLayoutWithOutLabel">
                用户充值会员后，其直推上级和间推上级得到的充值会员收益比例。<br/>
                例：直推上级收益（%）=50%，间推上级收益（%）=20%，A推B，B推C，C充值了会员，花了1块钱，A的会员奖励=100*20%=20 钻石，B的会员奖励=100*50%=50 钻石
              </a-form-model-item>
              <a-form-model-item v-bind="formItemLayoutWithOutLabel">
                <a-button type="primary" style="width: 150px;" @click="submitForm">确认修改</a-button>
              </a-form-model-item>
            </a-col>
          </a-row>
        </a-card>
      </a-form-model>
    </a-spin>
  </a-card>
</template>

<script>
import { httpAction, getAction } from '@/api/manage'
export default {
  name: 'MemberRewards',
  components: {},
  data () {
    return {
      confirmLoading:false,
      model: {
      },
      validatorRules: {
        SocialBenefits: [
          { required: true, message: '请输入社交收益(%)!',name:'社交收益'},
        ],
        SuperiorBenefits: [
          { required: true, message: '请输入直推上级收益(%)!',name:'直推上级收益'},
        ],
        UnSuperiorBenefits: [
          { required: true, message: '请输入间推上级收益(%)!',name:'间推上级收益'},
        ],
      },
      labelCol: {
        xs: { span: 24 },
        sm: { span: 3 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 8 },
      },
      formItemLayoutWithOutLabel: {
        wrapperCol: {
          xs: { span: 24, offset: 0 },
          sm: { span: 20, offset: 3 },
        },
      },
  }
  },
  created() {
    this.getSystemConfigMap();
  },
  methods: {
    //获取回显数据
    getSystemConfigMap(){
      getAction('/system/systemConfig/getSystemConfigMap').then((res)=>{
        if(res.success){
          this.model=res.result;
        }
      })
    },
    //保存数据
    submitForm () {
      const that = this;
      // 触发表单验证
      this.$refs.form.validate(valid => {
        if (valid) {
          that.confirmLoading = true;
          let httpurl = '/system/systemConfig/saveOrUpdate';
          let method = 'post';
          let dataList=[];
          //格式化数据
          for(let key in this.model){
            let obj={};
            obj.code=key;
            obj.value=this.model[key];
            if(that.validatorRules[key]){
              obj.title=that.validatorRules[key][0].name;
              dataList.push(obj)
            }
          }
          httpAction(httpurl,dataList,method).then((res)=>{
            if(res.success){
              that.$message.success(res.message);
              that.$emit('ok');
            }else{
              that.$message.warning(res.message);
            }
          }).finally(() => {
            that.confirmLoading = false;
          })
        }

      })
    },
  }
}
</script>

<style scoped>

</style>